<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.io.*"%>
<html>
    <body>
        <%
                   try{
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        //
                    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/news", "root", "root");
                    Statement stmt = con.createStatement();
                    ResultSet rs = null;
        //
                    String id = (String)request.getParameter("id");
        //
                    String sql = "select picfile from news WHERE id='" + id + "'";
        //
                    rs = stmt.executeQuery(sql);
                    while (rs.next()) {
                        ServletOutputStream sout = response.getOutputStream();
                        String url=application.getRealPath("/");
                        //String realPath=request.getContextPath();
                        FileOutputStream sfile=new FileOutputStream(url+"Figure/"+id+".jpg");
                        //System.out.println("realPath"+realPath);
        //
                        InputStream in = rs.getBinaryStream(1);
                        byte b[] = new byte[10240];
                        int len;
                        while((len=in.read(b)) != -1){
                            sout.write(b, 0, len);
                            sfile.write(b, 0, len);
                            }
        //
                        sout.flush();
                        sfile.flush();
        //
                        sout.close();
                        sfile.close();
                    }
                    con.close();
                    }catch(Exception e){
                      System.out.println("none pic");
                    }
                   out.clear();
                   out = pageContext.pushBody();
        %>
    </body>
</html>

